import { getActives} from '../../api/api.js';


const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    parameter: {
      'navbar': '1',
      'return': '1',
      'title': '最新公告',
    },
    list:[],
    page:1,
    limit:10,
    loadend:false,
    loading:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },

  getList(){
    let that = this
    if(this.data.loading||this.data.loadend){
      return
    }
    this.setData({
      loading:true,
    })
    getActives({page:this.data.page,limit:this.data.limit}).then(res=>{
      var list = that.data.list;
      var loadend = list.length < that.data.limit;
      if (that.data.page == 1) {
        list = res.data.data
      } else {
        list.push(...res.data)
      }
        that.setData({
          list:list,
          loadend:loadend,
          loading:false,
          page: that.data.page + 1,
        })
    })
  },
  
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList()
  },
})